package com.example.demo.util;

/**
 * 分页
 * 
 * @author zhou
 */
public class PageUtil {
  private static int maxLimit = 100;

  private int page = 1;
  private int limit = 20;
  private int start = 0;

  public PageUtil() {

  }

  public PageUtil(int page, int limit) {
    this.setPage(page);
    this.setLimit(limit);
    this.setStart((this.page - 1) * this.limit);
  }

  public int getStart() {
    return start;
  }

  public void setStart(int start) {
    this.start = start;
  }

  public int getPage() {
    return page;
  }

  public void setPage(int page) {
    if (page < 1) {
      page = 1;
    }
    this.page = page;
  }

  public int getLimit() {
    return limit;
  }

  /**
   * 最大100条
   * 
   * @param limit
   */
  public void setLimit(int limit) {
    if (limit < 1) {
      limit = 1;
    } else if (limit > maxLimit) {
      limit = maxLimit;
    }
    this.limit = limit;
  }

}
